import pygame
import configparser
from pygame.locals import *


class Fly:
    def __init__(self):
        config = configparser.ConfigParser()  # 实例化配置加载组件
        config.read('./config/cfg.ini')  # 加载配置
        self.init_x = config.getint('fly-config', 'init_x')  # 初始位置
        self.init_y = config.getint('fly-config', 'init_y')
        self.move_speed_x = config.getint('fly-config', 'move_speed_x')    # X轴移动速度
        self.move_speed_y = config.getint('fly-config', 'move_speed_y')    # Y轴移动速度

    # 移动方法
    def move(self):
        for event in pygame.event.get():
            # 判断是否退出
            if event.type == QUIT:
                exit()
            elif event.type == KEYDOWN:
                if event.key == K_LEFT:
                    if self.init_x < -50:
                        continue
                    self.init_x -= self.move_speed_x
                elif event.key == K_RIGHT:
                    if self.init_x > 300:
                        continue
                    self.init_x += self.move_speed_x
                    print('right')
                elif event.key == K_UP:
                    if self.init_y < -50:
                        continue
                    self.init_y -= self.move_speed_y
                elif event.key == K_DOWN:
                    if self.init_y > 550:
                        continue
                    self.init_y += self.move_speed_y
                elif event.key == K_SPACE:
                    print('space')


if __name__ == '__main__':
    f = Fly()
